package main

import (
	"flag"
	"log"
	"stormragetech/dawn/conf"
	"stormragetech/dawn/member"
	"time"

	"github.com/smallnest/rpcx/serverplugin"

	metrics "github.com/rcrowley/go-metrics"
	"github.com/smallnest/rpcx/server"
)

func main() {
	flag.Parse()

	s := server.NewServer()
	addRegistryPlugin(s)

	s.RegisterName("UserRPC", new(member.UserRPC), "")
	s.Serve("tcp", conf.Conf.RPCMemberAddr)
}

func addRegistryPlugin(s *server.Server) {

	r := &serverplugin.ZooKeeperRegisterPlugin{
		ServiceAddress:   "tcp@" + conf.Conf.RPCMemberAddr,
		ZooKeeperServers: []string{conf.Conf.ZkAddr},
		BasePath:         conf.Conf.RPCBasePath,
		Metrics:          metrics.NewRegistry(),
		UpdateInterval:   time.Minute,
	}
	err := r.Start()
	if err != nil {
		log.Fatal(err)
	}
	s.Plugins.Add(r)
}
